$(function() {
    /*var e = axios.create({
        //baseURL: "http://jd.toutiao.chinaso.com/phonecard",
        //baseURL: "http://www.zoptest.com/index.php/Mobile/Indexgz",
        baseURL: "http://drhd.liao588.top/index.php/Mobile/Indexgz",
        timeout: 1e4
    });*/
    
    function t() {
        this.el = $('<div class="loading" />'),
        this.el.hide(),
        this.el.append('\n            <div>\n                <svg version="1.1" id="loader-1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="40px" height="40px" viewBox="0 0 40 40" enable-background="new 0 0 40 40" xml:space="preserve">\n                    <path opacity="0.2" fill="#fff" d="M20.201,5.169c-8.254,0-14.946,6.692-14.946,14.946c0,8.255,6.692,14.946,14.946,14.946\n                        s14.946-6.691,14.946-14.946C35.146,11.861,28.455,5.169,20.201,5.169z M20.201,31.749c-6.425,0-11.634-5.208-11.634-11.634\n                        c0-6.425,5.209-11.634,11.634-11.634c6.425,0,11.633,5.209,11.633,11.634C31.834,26.541,26.626,31.749,20.201,31.749z"></path>\n                    <path fill="#fff" d="M26.013,10.047l1.654-2.866c-2.198-1.272-4.743-2.012-7.466-2.012h0v3.312h0\n                        C22.32,8.481,24.301,9.057,26.013,10.047z">\n                        <animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 20 20" to="360 20 20" dur="0.5s" repeatCount="indefinite"></animateTransform>\n                    </path>\n                </svg>\n            </div>\n        '),
        $("body").append(this.el)
    }
    /*e.interceptors.response.use(function(e) {
        if (200 <= e.status && e.status < 300) {
            if (!1 === e.data.success) throw new Error(e.data.data);
            return e.data
        }
        throw e
    }),*/
    $.request = function() {
        return e(0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : {})
    },
    $.toast = function(e) {
        return iziToast.show({
            backgroundColor: "rgba(0,0,0,.8)",
            position: "center",
            theme: "dark",
            animateInside: !1,
            pauseOnHover: !1,
            progressBar: !1,
            close: !1,
            drag: !1,
            message: e
        })
    },
    t.prototype.show = function() {
        this.el.show()
    },
    t.prototype.hide = function() {
        this.el.hide()
    },
    $.loading = new t,
    $.integerFixed = function(e, t) {
        var o = Math.pow(10, t);
        return (e = parseInt(e)) < o ? (e / o).toFixed(t).slice( - t) : e
    },
    $.dateFormat = function(e) {
        var t = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : "{yyyy}-{mm}-{dd} {hh}:{ii}";
        if (e instanceof Date) {
            var r = {
                y: e.getFullYear(),
                m: e.getMonth() + 1,
                a: e.getDay(),
                d: e.getDate(),
                h: e.getHours(),
                i: e.getMinutes(),
                s: e.getSeconds()
            };
            return t.replace(/{((n|y|x|m|a|d|h|i|s)+)}/g,
            function(e, t, o) {
                var n = r[o] || 0;
                return "a" === o ? ["日", "一", "二", "三", "四", "五", "六"][n] : $.integerFixed(n, t.length)
            })
        }
        return e
    },
    $.fn.countdown = function() {
        var e = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : "$s秒后可重发",
        t = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : 60,
        o = $(this),
        n = o.html(),
        r = t,
        a = setInterval(function() {
            0 < --r ? o.html(e.replace("$s", r)) : (clearInterval(a), o.removeClass("disabled").html(n))
        },
        1e3);
        o.addClass("disabled").html(e.replace("$s", r))
    }
}),
$(function() {
    var n = "981610241535",
    r = "08-2278-7595-9999";
    new MobileSelect({
        trigger: "#area",
        triggerDisplayData: !1,
        title: "选择区/县",
        keyMap: {
            id: "code",
            value: "name",
            childs: "children"
        },
        wheels: [{
            data: cityData
        }],
        callback: function(e, t) {
            $("#area .value").data("value", t.map(function(e) {
                return e.code
            })).html(t.map(function(e) {
                return e.name
            }).join(" ")).trigger("input")
        }
    }),
    new MobileSelect({
        trigger: "#attribution",
        triggerDisplayData: !1,
        title: "选择号码归属地",
        keyMap: {
            id: "ess",
            value: "name",
            childs: "children"
        },
        wheels: [{
            data: cityData.reduce(function(e, t) {
                var o = t.name,
                n = t.code,
                r = t.ess,
                a = t.children,
                i = {
                    name: o,
                    code: n,
                    ess: r
                };
                return a && (i.children = a.map(function(e) {
                    return {
                        name: e.name,
                        code: e.code,
                        ess: e.ess
                    }
                })),
                e.push(i),
                e
            },
            [])
        }],
        callback: function(e, t) {
            $("#attribution .value").data("value", t.map(function(e) {
                return e.ess
            })).html(t.map(function(e) {
                return e.name
            }).join(" ")).trigger("input")
        }
    });
    /*$.request({
        method: "post",
        url: "/getUser"
    }).then(function(e) {
        var user = JSON.stringify(e);
        $(".userCount").text(e.msg);
    });*/
    var i = {
        certName: "",
        contactNum: "",
        certNo: "",
        captcha: "",
        postProvinceCode: "",
        postCityCode: "",
        postDistrictCode: "",
        postAddr: "",
        provinceCode: "",
        cityCode: "",
        phoneNum: ""
    };
    function c(e, t) {
        var o = !(0 < arguments.length && void 0 !== e) || e,
        n = 1 < arguments.length && void 0 !== t ? t: [],
        r = 0 === n.length;
        if (!r && !n.includes("certName") || /^[\u2E80-\u9FFF]+$/.test(i.certName)) {
                if (!r && !n.includes("contactNum") || /(^(\d{3,4}-)?\d{7,8}$)|(^1[0-9]{10}$)/.test(i.contactNum))  {
                    if (! (r || n.includes("postProvinceCode") || n.includes("postCityCode") || n.includes("postDistrictCode")) || i.postProvinceCode && i.postCityCode && i.postDistrictCode) {
                            if (!r && !n.includes("postAddr") || i.postAddr.length) {return 1;}else{o && $.toast("请输入详细地址")}
                    }else{o && $.toast("请选择区/县")}
                }else{o && $.toast("请输入正确的联系电话")}
        }else{o && $.toast("请输入正确的姓名")}
    }
    $("#form .value").on("input",
    function(e) {
        var t = $(e.target);
        if (t.hasClass("postCode")) {
            var o = (t.data("value") || "").toString().split(",");
            i.postProvinceCode = o[0] || "",
            i.postCityCode = o[1] || "",
            i.postDistrictCode = o[2] || ""
            i.postcity=t.html();
        } else if (t.hasClass("getCode")) {
            var n = (t.data("value") || "").split(",");
            i.provinceCode = n[0] || "",
            i.cityCode = n[1] || ""
        } else if (t.hasClass("phoneNum")) i.phoneNum = (t.data("value") || "").toString();
        else {
            var r = $.trim(t.val());
            for (var a in i) if (t.hasClass(a)) {
                i[a] = r;
                break
            }
        }
        c(!1, ["certName", "contactNum"]) ? $("#certNo").show() : $("#certNo").hide()
    });
    var e = $(".main"),
    a = $("#submit .btn"),
    s = a.offset().top + a.height() -350 + e.width() / 1080 * 20  ;
    $(window).on("scroll",
    function(e) {
        var t = $(this),
        o = t.scrollTop() + t.height();
        a.addClass("fixed");
        /*console.log('top==='+ a.offset().top);
        console.log('height='+ a.height());*/
        /*console.log('sssss='+s);
        console.log('ooooo='+o);*/
        /*s <= o ? a.addClass("fixed") : a.removeClass("fixed")*/
    }).scroll(),
    $("#code").on("click",
    function() {
        var e = this;
        c(!0, ["certName", "contactNum", "certNo"]) && ($.loading.show(), $.request({
            method: "post",
            url: "/send",
            data: {
                channel: r,
                certId: i.certNo,
                contactNum: i.contactNum
            }
        }).then(function(e) {
            if ("0000" !== e.rspCode) throw new Error(e.rspDesc)
        }).then(function() {
            $(e).countdown(),
            $.loading.hide()
        }).
        catch(function(e) {
            $.toast(e && e.message || "短信验证码获取失败"),
            $.loading.hide()
        }))
    });
    var o = $("#phoneModal").remodal();
    function t() {
        return $.loading.show(),
        $.request({
            method: "post",
            url: "/SearchNos",
            data: {
                provinceCode: i.provinceCode,
                cityCode: i.cityCode,
                qryType: "02",
                searchCategory: "1",
                goodsId: n,
                searchType: "",
                searchValue: "",
                amounts: ""
            }
        }).then(function(e) {
            if (!e.body.numArray.length) throw new Error("未获取到有效的手机号码");
            var t = $("#phoneModal ul"),
            o = 10,
            n = 0;
            for (t.html(""); 0 < o;) {
                if (11 === e.body.numArray[n].toString().length) {
                    var r = $("<li/>");
                    r.data("code", e.body.numArray[n]),
                    r.text(e.body.numArray[n]),
                    t.append(r),
                    o--
                }
                n++
            }
            $.loading.hide()
        }).
        catch(function(e) {
            throw $.toast(e && e.message || "手机号码获取失败"),
            $.loading.hide(),
            e
        })
    }
    $("#phoneSelect").on("click",
    function() {
        c(!0, ["provinceCode", "cityCode"]) && t().then(function() {
            return o.open()
        })
    }),
    $("#phoneModal .ensure").on("click", t),
    $("#phoneModal").on("click", "li",
    function(e) {
        var t = $(e.target).data("code");
        $("#phoneSelect .value").data("value", t).html(t).trigger("input"),
        o.close()
    })
    $("#submit .btn").on("click",
    function() {
        //$.toast("请输入正确的姓名");
        /*alert(/(^(\d{3,4}-)?\d{7,8}$)|(^1[0-9]{10}$)/.test(i.contactNum));*/
        /*alert(apiUri);
        return false;*/
        var certName = $(".certName").val();
        if (c(!0)) {

            
            $.loading.show(),
            $.ajax({
                type: "post",
                url: apiUrl+"/subcardinfo",
                data: {
                    name: i.certName,
                    mobile: i.contactNum,
                    address: i.postcity+i.postAddr
                },
                dataType: "json",
                success: function(data){
                    console.log(data);
                     if (data.code == 200){
                        $.toast(data.msg)
                        /*location.href='./index.php?g=Wap&m=Kuaishou&a=wxpay&trade_no='+trade_no+'&money='+money;*/
                        $.loading.hide();
                        
                     }else{$.toast(data.msg),
                        $.loading.hide()} 
                  }
            })
        }
    })
});
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return decodeURIComponent(r[2]); // unescape替换为decodeURIComponent
    return null; //返回参数值
}